package cn.dgut.changeManager;

import cn.dgut.Entity.*;
import cn.dgut.Utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Modify_Ajax")
public class Modify_AjaxServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int page = Integer.parseInt(request.getParameter("page"));
        int id = Integer.parseInt(request.getParameter("id"));

        response.setContentType("application/json,charset=utf-8");
        response.setCharacterEncoding("UTF-8");
        JDBCUtils utils = new JDBCUtils();

        //重写toString()方法--> 输出json字符串
        if(page==0){
            User temp = (User) utils.queryOneData("User",id);
            response.getWriter().println(temp);
        }else if(page==1){
            Student temp = (Student) utils.queryOneData("Student",id);
            response.getWriter().println(temp);
        }else if(page==2){
            Teacher temp = (Teacher) utils.queryOneData("Teacher",id);
            response.getWriter().println(temp);
        }else if(page==3){
            Course temp = (Course) utils.queryOneData("Course",id);
            response.getWriter().println(temp);
        }else if(page==4){
            Select_Course temp = (Select_Course) utils.queryOneData("Select_Course",id);
            response.getWriter().println(temp);
        }else if(page==5){
            StudentWorks temp = (StudentWorks) utils.queryOneData("StudentWorks",id);
            response.getWriter().println(temp);
        }else if(page==6){
            Recruit temp = (Recruit) utils.queryOneData("Recruit",id);
            response.getWriter().println(temp);
        }else if(page==7){
            Teacher temp = (Teacher) utils.queryOneData("Resume",id);
            response.getWriter().println(temp);
        }else{
            return;
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}